<template>
  <div>

  </div>
</template>

<script lang="ts">
import { ref, defineComponent, getCurrentInstance,onMounted } from 'vue'
export default defineComponent({
  name: 'LogicOperation',
  setup: () => {
    let {ctx}:any = getCurrentInstance();

    onMounted(() => {
      console.log("逻辑运算");
      let r1 = eitherWay(101);
      let r2 = eitherWay(8);
      let r3 = eitherWay(7);
      console.log('eitherWay',r1,r2,r3);
      console.log('==================');
      let r4 = bothWay(11);
      let r5 = bothWay(12);
      let r6 = bothWay(4);
      console.log('bothWay',r4,r5,r6);
      console.log('==================');
      let r7 = allPassWay(14);
      let r8 = allPassWay(16);
      console.log('allPassWay',r7,r8);
      console.log('==================');
    })

    const gt10 = (x:number) => {
      return x>10;
    } 
    const even = (x:number) =>{
      return x%2==0;
    }
    const buff = (x:number)=>{
      return x<15;
    }

    const eitherWay = ctx.$R.either(gt10,even);
    //either:接受两个函数作为参数,只要一个返回为true,就返回true,否则返回false。相当于||运算
    const bothWay = ctx.$R.both(gt10,even);
    //both: 接受两个函数作为参数,只有他们都返回true,才返回true,否则返回false,相当于&&运算
    const allPassWay = ctx.$R.allPass([gt10,even,buff]);
    // allPass：接受一个数组的函数作为参数,只有每个都返回true,否则返回false,算是加强版的bothWay
    return { gt10,even,buff,eitherWay,bothWay,allPassWay }
  }
})
</script>

<style scoped>
a {
  color: #42b983;
}

label {
  margin: 0 0.5em;
  font-weight: bold;
}

code {
  background-color: #eee;
  padding: 2px 4px;
  border-radius: 4px;
  color: #304455;
}
</style>
